home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / javax / swing / JTextField.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  8.0 KB  |  344 lines

  1. package javax.swing;
  2.  
  3. import java.awt.AWTEvent;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.EventQueue;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Insets;
  10. import java.awt.Rectangle;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.InputEvent;
  14. import java.beans.PropertyChangeListener;
  15. import java.io.IOException;
  16. import java.io.ObjectOutputStream;
  17. import javax.accessibility.AccessibleContext;
  18. import javax.swing.text.Document;
  19. import javax.swing.text.JTextComponent;
  20. import javax.swing.text.PlainDocument;
  21. import javax.swing.text.TextAction;
  22.  
  23. public class JTextField extends JTextComponent implements SwingConstants {
  24.    private Action action;
  25.    private PropertyChangeListener actionPropertyChangeListener;
  26.    public static final String notifyAction = "notify-field-accept";
  27.    private BoundedRangeModel visibility;
  28.    private int horizontalAlignment;
  29.    private int columns;
  30.    private int columnWidth;
  31.    private String command;
  32.    private static final Action[] defaultActions = new Action[]{new NotifyAction()};
  33.    private static final String uiClassID = "TextFieldUI";
  34.  
  35.    public JTextField() {
  36.       this((Document)null, (String)null, 0);
  37.    }
  38.  
  39.    public JTextField(String var1) {
  40.       this((Document)null, var1, 0);
  41.    }
  42.  
  43.    public JTextField(int var1) {
  44.       this((Document)null, (String)null, var1);
  45.    }
  46.  
  47.    public JTextField(String var1, int var2) {
  48.       this((Document)null, var1, var2);
  49.    }
  50.  
  51.    public JTextField(Document var1, String var2, int var3) {
  52.       this.horizontalAlignment = 10;
  53.       if (var3 < 0) {
  54.          throw new IllegalArgumentException("columns less than zero.");
  55.       } else {
  56.          this.visibility = new DefaultBoundedRangeModel();
  57.          this.visibility.addChangeListener(new ScrollRepainter(this));
  58.          this.columns = var3;
  59.          if (var1 == null) {
  60.             var1 = this.createDefaultModel();
  61.          }
  62.  
  63.          this.setDocument(var1);
  64.          if (var2 != null) {
  65.             this.setText(var2);
  66.          }
  67.  
  68.       }
  69.    }
  70.  
  71.    public String getUIClassID() {
  72.       return "TextFieldUI";
  73.    }
  74.  
  75.    public void setDocument(Document var1) {
  76.       if (var1 != null) {
  77.          var1.putProperty("filterNewlines", Boolean.TRUE);
  78.       }
  79.  
  80.       super.setDocument(var1);
  81.    }
  82.  
  83.    public boolean isValidateRoot() {
  84.       Container var1 = this.getParent();
  85.       return !(var1 instanceof JViewport);
  86.    }
  87.  
  88.    public int getHorizontalAlignment() {
  89.       return this.horizontalAlignment;
  90.    }
  91.  
  92.    public void setHorizontalAlignment(int var1) {
  93.       if (var1 != this.horizontalAlignment) {
  94.          int var2 = this.horizontalAlignment;
  95.          if (var1 != 2 && var1 != 0 && var1 != 4 && var1 != 10 && var1 != 11) {
  96.             throw new IllegalArgumentException("horizontalAlignment");
  97.          } else {
  98.             this.horizontalAlignment = var1;
  99.             this.firePropertyChange("horizontalAlignment", var2, this.horizontalAlignment);
  100.             this.invalidate();
  101.             this.repaint();
  102.          }
  103.       }
  104.    }
  105.  
  106.    protected Document createDefaultModel() {
  107.       return new PlainDocument();
  108.    }
  109.  
  110.    public int getColumns() {
  111.       return this.columns;
  112.    }
  113.  
  114.    public void setColumns(int var1) {
  115.       int var2 = this.columns;
  116.       if (var1 < 0) {
  117.          throw new IllegalArgumentException("columns less than zero.");
  118.       } else {
  119.          if (var1 != var2) {
  120.             this.columns = var1;
  121.             this.invalidate();
  122.          }
  123.  
  124.       }
  125.    }
  126.  
  127.    protected int getColumnWidth() {
  128.       if (this.columnWidth == 0) {
  129.          FontMetrics var1 = this.getFontMetrics(this.getFont());
  130.          this.columnWidth = var1.charWidth('m');
  131.       }
  132.  
  133.       return this.columnWidth;
  134.    }
  135.  
  136.    public Dimension getPreferredSize() {
  137.       Dimension var1 = super.getPreferredSize();
  138.       if (this.columns != 0) {
  139.          Insets var2 = this.getInsets();
  140.          var1.width = this.columns * this.getColumnWidth() + var2.left + var2.right;
  141.       }
  142.  
  143.       return var1;
  144.    }
  145.  
  146.    public void setFont(Font var1) {
  147.       super.setFont(var1);
  148.       this.columnWidth = 0;
  149.    }
  150.  
  151.    public synchronized void addActionListener(ActionListener var1) {
  152.       this.listenerList.add(ActionListener.class, var1);
  153.    }
  154.  
  155.    public synchronized void removeActionListener(ActionListener var1) {
  156.       if (var1 != null && this.getAction() == var1) {
  157.          this.setAction((Action)null);
  158.       } else {
  159.          this.listenerList.remove(ActionListener.class, var1);
  160.       }
  161.  
  162.    }
  163.  
  164.    public synchronized ActionListener[] getActionListeners() {
  165.       return (ActionListener[])this.listenerList.getListeners(ActionListener.class);
  166.    }
  167.  
  168.    protected void fireActionPerformed() {
  169.       Object[] var1 = this.listenerList.getListenerList();
  170.       int var2 = 0;
  171.       AWTEvent var3 = EventQueue.getCurrentEvent();
  172.       if (var3 instanceof InputEvent) {
  173.          var2 = ((InputEvent)var3).getModifiers();
  174.       } else if (var3 instanceof ActionEvent) {
  175.          var2 = ((ActionEvent)var3).getModifiers();
  176.       }
  177.  
  178.       ActionEvent var4 = new ActionEvent(this, 1001, this.command != null ? this.command : this.getText(), EventQueue.getMostRecentEventTime(), var2);
  179.  
  180.       for(int var5 = var1.length - 2; var5 >= 0; var5 -= 2) {
  181.          if (var1[var5] == ActionListener.class) {
  182.             ((ActionListener)var1[var5 + 1]).actionPerformed(var4);
  183.          }
  184.       }
  185.  
  186.    }
  187.  
  188.    public void setActionCommand(String var1) {
  189.       this.command = var1;
  190.    }
  191.  
  192.    public void setAction(Action var1) {
  193.       Action var2 = this.getAction();
  194.       if (this.action == null || !this.action.equals(var1)) {
  195.          this.action = var1;
  196.          if (var2 != null) {
  197.             this.removeActionListener(var2);
  198.             var2.removePropertyChangeListener(this.actionPropertyChangeListener);
  199.             this.actionPropertyChangeListener = null;
  200.          }
  201.  
  202.          this.configurePropertiesFromAction(this.action);
  203.          if (this.action != null) {
  204.             if (!this.isListener(ActionListener.class, this.action)) {
  205.                this.addActionListener(this.action);
  206.             }
  207.  
  208.             this.actionPropertyChangeListener = this.createActionPropertyChangeListener(this.action);
  209.             this.action.addPropertyChangeListener(this.actionPropertyChangeListener);
  210.          }
  211.  
  212.          this.firePropertyChange("action", var2, this.action);
  213.       }
  214.  
  215.    }
  216.  
  217.    private boolean isListener(Class var1, ActionListener var2) {
  218.       boolean var3 = false;
  219.       Object[] var4 = this.listenerList.getListenerList();
  220.  
  221.       for(int var5 = var4.length - 2; var5 >= 0; var5 -= 2) {
  222.          if (var4[var5] == var1 && var4[var5 + 1] == var2) {
  223.             var3 = true;
  224.          }
  225.       }
  226.  
  227.       return var3;
  228.    }
  229.  
  230.    public Action getAction() {
  231.       return this.action;
  232.    }
  233.  
  234.    protected void configurePropertiesFromAction(Action var1) {
  235.       AbstractAction.setEnabledFromAction(this, var1);
  236.       AbstractAction.setToolTipTextFromAction(this, var1);
  237.       this.setActionCommandFromAction(var1);
  238.    }
  239.  
  240.    protected void actionPropertyChanged(Action var1, String var2) {
  241.       if (var2 == "ActionCommandKey") {
  242.          this.setActionCommandFromAction(var1);
  243.       } else if (var2 == "enabled") {
  244.          AbstractAction.setEnabledFromAction(this, var1);
  245.       } else if (var2 == "ShortDescription") {
  246.          AbstractAction.setToolTipTextFromAction(this, var1);
  247.       }
  248.  
  249.    }
  250.  
  251.    private void setActionCommandFromAction(Action var1) {
  252.       this.setActionCommand(var1 == null ? null : (String)var1.getValue("ActionCommandKey"));
  253.    }
  254.  
  255.    protected PropertyChangeListener createActionPropertyChangeListener(Action var1) {
  256.       return new TextFieldActionPropertyChangeListener(this, var1);
  257.    }
  258.  
  259.    public Action[] getActions() {
  260.       return TextAction.augmentList(super.getActions(), defaultActions);
  261.    }
  262.  
  263.    public void postActionEvent() {
  264.       this.fireActionPerformed();
  265.    }
  266.  
  267.    public BoundedRangeModel getHorizontalVisibility() {
  268.       return this.visibility;
  269.    }
  270.  
  271.    public int getScrollOffset() {
  272.       return this.visibility.getValue();
  273.    }
  274.  
  275.    public void setScrollOffset(int var1) {
  276.       this.visibility.setValue(var1);
  277.    }
  278.  
  279.    public void scrollRectToVisible(Rectangle var1) {
  280.       Insets var2 = this.getInsets();
  281.       int var3 = var1.x + this.visibility.getValue() - var2.left;
  282.       int var4 = var3 + var1.width;
  283.       if (var3 < this.visibility.getValue()) {
  284.          this.visibility.setValue(var3);
  285.       } else if (var4 > this.visibility.getValue() + this.visibility.getExtent()) {
  286.          this.visibility.setValue(var4 - this.visibility.getExtent());
  287.       }
  288.  
  289.    }
  290.  
  291.    boolean hasActionListener() {
  292.       Object[] var1 = this.listenerList.getListenerList();
  293.  
  294.       for(int var2 = var1.length - 2; var2 >= 0; var2 -= 2) {
  295.          if (var1[var2] == ActionListener.class) {
  296.             return true;
  297.          }
  298.       }
  299.  
  300.       return false;
  301.    }
  302.  
  303.    private void writeObject(ObjectOutputStream var1) throws IOException {
  304.       var1.defaultWriteObject();
  305.       if (this.getUIClassID().equals("TextFieldUI")) {
  306.          byte var2 = JComponent.getWriteObjCounter(this);
  307.          --var2;
  308.          JComponent.setWriteObjCounter(this, var2);
  309.          if (var2 == 0 && this.ui != null) {
  310.             this.ui.installUI(this);
  311.          }
  312.       }
  313.  
  314.    }
  315.  
  316.    protected String paramString() {
  317.       String var1;
  318.       if (this.horizontalAlignment == 2) {
  319.          var1 = "LEFT";
  320.       } else if (this.horizontalAlignment == 0) {
  321.          var1 = "CENTER";
  322.       } else if (this.horizontalAlignment == 4) {
  323.          var1 = "RIGHT";
  324.       } else if (this.horizontalAlignment == 10) {
  325.          var1 = "LEADING";
  326.       } else if (this.horizontalAlignment == 11) {
  327.          var1 = "TRAILING";
  328.       } else {
  329.          var1 = "";
  330.       }
  331.  
  332.       String var2 = this.command != null ? this.command : "";
  333.       return super.paramString() + ",columns=" + this.columns + ",columnWidth=" + this.columnWidth + ",command=" + var2 + ",horizontalAlignment=" + var1;
  334.    }
  335.  
  336.    public AccessibleContext getAccessibleContext() {
  337.       if (this.accessibleContext == null) {
  338.          this.accessibleContext = new AccessibleJTextField(this);
  339.       }
  340.  
  341.       return this.accessibleContext;
  342.    }
  343. }
  344.